<?php

/**
 * This is the model class for table "biaya_prov".
 *
 * The followings are the available columns in table 'biaya_prov':
 * @property integer $id_biaya_prov
 * @property integer $id_provinsi
 * @property integer $id_type_dinas
 * @property double $biaya_harian
 * @property double $biaya_penginapan
 *
 * The followings are the available model relations:
 * @property Provinsi $idProvinsi
 * @property TypeDinas $idTypeDinas
 * @property Tim[] $tims
 */
class BiayaProv extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return BiayaProv the static model class
	 */
	public $nama_type_dinas,$nama_prov;
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'biaya_prov';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id_provinsi, id_type_dinas, biaya_harian, biaya_penginapan', 'required'),
			array('id_provinsi, id_type_dinas', 'numerical', 'integerOnly'=>true),
			array('biaya_harian, biaya_penginapan', 'numerical'),
			array('nama_type_dinas,nama_prov', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id_biaya_prov, id_provinsi, id_type_dinas, biaya_harian, biaya_penginapan', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'idProvinsi' => array(self::BELONGS_TO, 'Provinsi', 'id_provinsi'),
			'idTypeDinas' => array(self::BELONGS_TO, 'TypeDinas', 'id_type_dinas'),
			'tims' => array(self::HAS_MANY, 'Tim', 'id_biaya_prov'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_biaya_prov' => 'Id Biaya Prov',
			'id_provinsi' => 'Provinsi',
			'id_type_dinas' => 'Type Dinas',
			'biaya_harian' => 'Biaya Harian',
			'biaya_penginapan' => 'Biaya Penginapan',
			'nama_type_dinas' => 'Type Dinas',
			'nama_prov' => 'Provinsi',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;
		$criteria->alias = 'bp';
        $criteria->select = 'bp.*,prov.nama_prov,tp.nama_type_dinas'; 
		$criteria->join = ' inner join provinsi prov on prov.id_provinsi = bp.id_provinsi
							inner join type_dinas tp on tp.id_type_dinas = bp.id_type_dinas';
		$criteria->compare('id_biaya_prov',$this->id_biaya_prov);
		$criteria->compare('id_provinsi',$this->id_provinsi);
		$criteria->compare('id_type_dinas',$this->id_type_dinas);
		$criteria->compare('biaya_harian',$this->biaya_harian,true);
		$criteria->compare('biaya_penginapan',$this->biaya_penginapan,true);
		$criteria->compare('nama_type_dinas',$this->nama_type_dinas,true);
		$criteria->compare('nama_prov',$this->nama_prov,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
			'sort'=>array(
				  'attributes'=>array(
						 'biaya_penginapan'=>array(
							 'asc'=>'biaya_penginapan',
							 'desc'=>'biaya_penginapan DESC',
						  ),
						  'biaya_harian'=>array(
							 'asc'=>'biaya_harian',
							 'desc'=>'biaya_harian DESC',
						  ),
						  'nama_type_dinas'=>array(
							 'asc'=>'nama_type_dinas',
							 'desc'=>'nama_type_dinas DESC',
						  ),
						  'nama_prov'=>array(
							 'asc'=>'nama_prov',
							 'desc'=>'nama_prov DESC',
						  )
				  )
			  ),
		));
	}
}